package com.ruitu.health_2.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_2.mvp.model.CommonModel;
import com.ruitu.health_2.ui.fragment.ComActivityListFragment;
import com.ruitu.health_2.ui.fragment.ComArticleListFragment;
import com.ruitu.health_2.ui.fragment.ComBookListFragment;
import com.ruitu.health_2.ui.fragment.ComProListFragment;
import com.ruitu.health_2.ui.fragment.ComReadListFragment;
import com.ruitu.health_2.ui.fragment.ComVideoListFragment;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.article.Article;
import com.ruitu.router_module.bean.home.AdvertContent;
import com.ruitu.router_module.bean.home.ReadPartie;
import com.ruitu.router_module.bean.product.Activity;
import com.ruitu.router_module.bean.product.Book;
import com.ruitu.router_module.bean.product.ProHome;
import com.ruitu.router_module.bean.product.Video;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class CommonPresenter {

    public static class ComProListP extends BasePresenter<ComProListFragment, CommonModel.ComProListM> {

        public Disposable reqProListByPos(String posId, int size, int num) {
            return m.reqProListByPos(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<AdvertContent<ProHome>>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<AdvertContent<ProHome>>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(1, true, pageResult.getData());
                    } else {
                        ToastUtils.showShort(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }

    public static class ComReadListP extends BasePresenter<ComReadListFragment, CommonModel.ComReadListM> {

        public Disposable reqReadListByPos(String posId, int size, int num) {
            return m.reqReadListByPos(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<AdvertContent<ReadPartie>>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<AdvertContent<ReadPartie>>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(1, true, pageResult.getData());
                    } else {
                        ToastUtils.showShort(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }

    public static class ComBookListP extends BasePresenter<ComBookListFragment, CommonModel.ComBookListM> {

        public Disposable reqBookListByPos(String posId, int size, int num) {
            return m.reqBookListByPos(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<AdvertContent<Book>>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<AdvertContent<Book>>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(1, true, pageResult.getData());
                    } else {
                        ToastUtils.showShort(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }

    public static class ComArticleListP extends BasePresenter<ComArticleListFragment, CommonModel.ComArticleListM> {

        public Disposable reqBookListByPos(String posId, int size, int num) {
            return m.reqArticleListByPos(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<AdvertContent<Article>>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<AdvertContent<Article>>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(1, true, pageResult.getData());
                    } else {
                        ToastUtils.showShort(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }

    public static class ComVideoListP extends BasePresenter<ComVideoListFragment, CommonModel.ComVideoListM> {

        public Disposable reqVideoListByPos(String posId, int size, int num) {
            return m.reqVideoListByPos(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<AdvertContent<Video>>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<AdvertContent<Video>>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(1, true, pageResult.getData());
                    } else {
                        ToastUtils.showShort(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }

    public static class ComActivityListP extends BasePresenter<ComActivityListFragment, CommonModel.ComActivityListM> {

        public Disposable reqActivityListByPos(String posId, int size, int num) {
            return m.reqActivityListByPos(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<AdvertContent<Activity>>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<AdvertContent<Activity>>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(1, true, pageResult.getData());
                    } else {
                        ToastUtils.showShort(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }
}